package com.scedu.config;

import org.springframework.util.StringUtils;
import org.springframework.web.servlet.LocaleResolver;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Locale;

public class MyLocaleResolver implements LocaleResolver {
    //请求解析
    @Override
    public Locale resolveLocale(HttpServletRequest request) {
        //获取请求中的lang参数
        String lang = request.getParameter("lang");
        Locale aDefault = Locale.getDefault();
        //如果lang不为空，请求的链接携带了国际化的参数
        if (!StringUtils.isEmpty(lang)){
            String[] s = lang.split("_");
            aDefault = new Locale(s[0], s[1]);

        }
        return aDefault;
    }

    @Override
    public void setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale) {

    }
}
